package com.example.a22310.myapplication.Activity;
//红色的R解决不了
import android.app.Activity;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.provider.SyncStateContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


import com.example.a22310.myapplication.Beans.user;

import com.example.a22310.myapplication.ViewModel.User.LoginViewModel;
import com.example.a22310.myapplication.databinding.ActivityLoginBinding;

//登陆页


public class LoginActivity extends AppCompatActivity {
    ActivityLoginBinding binding;
    LoginViewModel lvm;
    private user user=new user();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_login);
        EditText mPasswordView = (EditText) findViewById(R.id.password);
        /*
        对密码监听
         */
        mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
                if (id == R.id.login || id == EditorInfo.IME_NULL) {
                    lvm.attemptLogin();
                    return true;
                }
                return false;
            }
        });
        lvm = new LoginViewModel(this, binding);
    }




    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Tencent.onActivityResultData(requestCode, resultCode, data, new LoginUiListener(LoginActivity.this));

        if(requestCode == SyncStateContract.Constants.REQUEST_API) {
            if(resultCode == SyncStateContract.Constants.REQUEST_LOGIN) {
                Tencent.handleResultData(data,  new LoginUiListener(LoginActivity.this));
            }
        }

    }
}
